package snake.model;

import snake.common.GameImage;
import snake.enums.Direction;

import java.awt.*;
import java.awt.event.KeyEvent;

public class SnakeHead extends Entity {
    private Direction direction;

    public SnakeHead(Direction direction, int x, int y) {
        this.direction = direction;
        this.img = headerImage();
        this.x = x;
        this.y = y;
    }


    private Image headerImage() {
        switch (direction) {
            case UP:
                return GameImage.HEAD_UP;
            case DOWN:
                return GameImage.HEAD_DOWN;
            case LEFT:
                return GameImage.HEAD_LEFT;
            default:
                return GameImage.HEAD_RIGHT;
        }
    }

    public void changeDirection(int keyCode) {
        switch (keyCode) {
            case KeyEvent.VK_A:
                if (direction != Direction.RIGHT) {
                    direction = Direction.LEFT;
                    img = GameImage.HEAD_LEFT;
                }
                break;
            case KeyEvent.VK_D:
                if (direction != Direction.LEFT) {
                    direction = Direction.RIGHT;
                    img = GameImage.HEAD_RIGHT;
                }
                break;
            case KeyEvent.VK_W:
                if (direction != Direction.DOWN) {
                    direction = Direction.UP;
                    img = GameImage.HEAD_UP;
                }
                break;
            case KeyEvent.VK_S:
                if (direction != Direction.UP) {
                    direction = Direction.DOWN;
                    img = GameImage.HEAD_DOWN;
                }
                break;
            default:
                break;
        }
    }


    public Direction getDirection() {
        return direction;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }
}
